<template>
	<view class="content">
		<button type="default" @click="szw">1111</button>
		<span>uid is {{userId}}</span>
		<!-- 搜索 -->
		<view style="flex-direction: row;display: flex;background-color: #FFFFFF;align-items: center;padding: 12px;">
			<view
				style="display: flex;align-items: center;flex: 1;background-color: #f5f5f5;height: 36px;border-radius: 18px;padding-left: 12px;padding-right: 12px;">
				<text class="iconfont icon-sousuo" style="font-size: 20px;color: #999999;margin-right: 5px;"></text>
				<input type="text" value="" style="flex: 1;font-size: 14px;" placeholder="请输入搜索关键词" />
			</view>
		</view>
		<!-- 九宫格 -->
		<view class="" style="display: flex;flex-direction: row;flex-wrap: wrap;">
			<view v-if="idx != 5" class="" @click="itemClick(idx)" v-for="(obj,idx) in enterItems" :key="idx"
				style="width: calc(25% - 20px);padding: 10px;">
				<view style="padding: 5px;flex: 1;display: flex;flex-direction: column;
					justify-content: center;align-items: center;background-color: #FFFFFF;">
					<image :src="obj.icon" style="width: 48px;height: 48px;" mode=""></image>
					<label for="" style="font-size: 12px;margin-top: 5px;">{{obj.label}}</label>
				</view>
			</view>
		</view>

		<!-- 今日跟进 -->
		<view class="" style="display: flex;padding-left: 12px;padding-right: 12px;">
			<!-- left -->
			<view class="" style="flex: 1;">
				<view class="" style="flex: 1;display: flex;align-items: center;padding-right: 12px;">
					<text style="flex: 1;font-size: 12px;">今日跟进</text>
					<text style="font-size: 23px;font-weight: bold;color: #007AFF;">55</text>
				</view>
				<text style="font-size: 12px;color: #007AFF;">查看大学招生数据</text>
				<text style="font-size: 12px;color: #007AFF;" class="iconfont icon-arrow-right"></text>
			</view>
			<!-- right -->
			<view class="" style="flex: 1;display: flex;flex-direction: column;align-items: center;"
				@click="loadSalesInfo()">
				<image :src="require('@/static/home/home_loudou.png')" style="width: 20px;height: 20px;" mode="">
				</image>
				<text style="font-size: 13px;margin-top: 10px;">查看销售漏斗</text>
			</view>
		</view>

		<view style="height: 1px;background-color: #ebebeb;margin-top: 12px;"></view>

		<!-- record -->
		<!-- title -->
		<view
			style="padding: 12px;display: flex;flex-direction: row;align-items: center;justify-content: space-between;">
			<text style="font-size: 16px;font-weight: bold;">工作台消息提醒</text>
			<view style="display: flex;align-items: center;">
				<text class="iconfont icon-shanchu" style="margin-right: 5px;"></text>
				<text style="font-size: 12px;">清空</text>
			</view>
		</view>

		<!-- content -->
		<view style="padding-left: 12px;padding-right: 12px;" v-for="idx in 20">
			<span style="font-size: 14px;">【学校管理】</span>
			<span style="font-size: 14px;">四川大学四川大学四川大学四川大学四川大学四川大学</span>
			<view style="font-size: 12px;margin-top: 5px;color: #999999;">2021年9月13日18:31:13</view>
			<view style="height: 1px;background-color: #ebebeb;margin-top: 12px;"></view>
		</view>

	</view>
</template>

<script>
	import {
		getAuthorizeUrl,
		getuserinfo,
		Login
	} from "@/api/login.js"
	export default {
		data() {
			return {
				code: undefined,
				showtext: "",
				title: 'Hello',
				uid: '',
				userId:'',
				enterItems: [{
						label: "学校",
						icon: require("@/static/home/home01.png"),
					},
					{
						label: "教师",
						icon: require("@/static/home/home02.png")
					},
					{
						label: "学期",
						icon: require("@/static/home/home03.png")
					},
					{
						label: "课程",
						icon: require("@/static/home/home04.png")
					},
					{
						label: "学生",
						icon: require("@/static/home/home05.png")
					},
					{
						label: "商机",
						icon: require("@/static/home/home06.png")
					},
					{
						label: "订单",
						icon: require("@/static/home/home07.png")
					},
					{
						label: "渠道",
						icon: require("@/static/home/home08.png")
					},
				]
			}
		},

		mounted() {
			// let {
			// 	token,
			// 	tokenKey
			// } = uni.getStorageSync("loginInfo")
			// if (token == undefined) {
			// 	let hascode = this.getQueryVariable('code')
			// 	if (hascode == false) {
			// 		this.netGetLink()
			// 	} else {
			// 		this.code = hascode
			// 		this.netGetUID();
			// 	}
			// } else {
			// 	this.showtext = token
			// }
		},



		methods: {
			szw(){
				jWeixin.invoke('getCurExternalContact', {}, function(res) {
					if (res.err_msg == "getCurExternalContact:ok") {
						uni.showToast({
							title: JSON.stringify(res),
							icon: "none"
						})
					} else {
						//错误处理
						uni.showToast({
							title: JSON.stringify(res),
							icon: "none",
							duration:5000
						})
					}
				});
			},
			
			
			itemClick(idx) {
				console.log(idx)
				if (idx == 0) {
					uni.navigateTo({
						url: "/pages/school/school"
					})
					return
				}
				if (idx == 1) {
					uni.navigateTo({
						url: "/pages/teacher/teacher"
					})
					return
				}
				if (idx == 2) {
					uni.navigateTo({
						url: "/pages/semester/semester"
					})
					return
				}
				if (idx == 3) {
					uni.navigateTo({
						url: "/pages/course/course"
					})
					return
				}
				if (idx == 4) {
					uni.navigateTo({
						url: "/pages/student/student"
					})
					return
				}
				if (idx == 5) {
					uni.navigateTo({
						url: "/pages/customer/customer"
					})
					return
				}
				if (idx == 6) {
					uni.navigateTo({
						url: "/pages/order_index/order_index"
					})
					return
				}
				if (idx == 7) {
					uni.navigateTo({
						url: "/pages/business/business"
					})
					return
				}
			},
			loadSalesInfo() {
				uni.navigateTo({
					url: "/pages/sales-info/sales-info"
				})
			},

			netLogin() {
				let self = this;
				Login({
					userId: this.uid
				}).then(res => {
					let {
						token,
						tokenKey
					} = res
					if (token != null && tokenKey != null) {
						uni.setStorageSync("loginInfo", {
							token,
							tokenKey
						})
					}
					self.showtext = JSON.stringify(res)
				}).catch(e => {
					uni.showToast({
						title: e
					})
				})
			},
			netGetUID() {
				let self = this;
				getuserinfo({
					code: this.code
				}).then(res => {
					let {
						UserId
					} = res.data
					self.uid = UserId
					self.netLogin()
				}).catch(e => {

				})
			},

			netGetLink() {
				let fi = {
					redirect_uri: encodeURIComponent("http://1047z5h204.zicp.vip/#/"),
					state: "test"
				}
				let self = this;
				getAuthorizeUrl(fi).then(res => {
					let {
						msg
					} = res;
					window.location.href = msg;
				}).catch(e => {
					uni.showToast({
						title: e
					})
				})
			},

			getQueryVariable(variable) {
				var query = window.location.search.substring(1);
				var vars = query.split("&");
				for (var i = 0; i < vars.length; i++) {
					var pair = vars[i].split("=");
					if (pair[0] == variable) {
						return pair[1];
					}
				}
				return (false);
			}
		}
	}
</script>

<style>
	.content {
		background-color: #FFFFFF;
		width: 100%;
	}
</style>
